<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>

        function getRandomcolor(flag) {
            if (flag) {//为true的话则颜色是#ffffff类型
                let arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']
                let str = '#'

                for (let i = 1; i <= 6; i++) {
                    let random1 = Math.floor(Math.random() * arr.length)
                    str += arr[random1]
                }
                return str
            } else {//为false的话为rgb(255,255,255)类型
                let r = Math.floor(Math.random() * 256)
                let g = Math.floor(Math.random() * 256)
                let b = Math.floor(Math.random() * 256)
                return `rgb(${r},${g},${b})`
                //记住是反引号 
            }
        }
        console.log(getRandomcolor(false));
        console.log(getRandomcolor());

    </script>
</body>

</html>